package com.jeesite.modules.otheroutbound.web;

import java.util.List;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.otheroutbound.entity.OtherOutboundHeader;
import com.jeesite.modules.otheroutbound.entity.OtherOutboundLines;
import com.jeesite.modules.otheroutbound.service.OtherOutboundHeaderService;

/**
 * 其它出库单Controller
 * @author 码脑洞
 * @version 2025-04-13
 */
@Controller
@RequestMapping(value = "${adminPath}/otheroutbound/header")
public class OtherOutboundHeaderController extends BaseController {

	@Autowired
	private OtherOutboundHeaderService otherOutboundHeaderService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public OtherOutboundHeader get(Long autoId, boolean isNewRecord) {
		return otherOutboundHeaderService.get(autoId, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("otheroutbound:header:view")
	@RequestMapping(value = {"list", ""})
	public String list(OtherOutboundHeader otherOutboundHeader, Model model) {
		model.addAttribute("otherOutboundHeader", otherOutboundHeader);
		return "modules/otheroutbound/otherOutboundHeaderList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("otheroutbound:header:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<OtherOutboundHeader> listData(OtherOutboundHeader otherOutboundHeader, HttpServletRequest request, HttpServletResponse response) {
		otherOutboundHeader.setPage(new Page<>(request, response));
		Page<OtherOutboundHeader> page = otherOutboundHeaderService.findPage(otherOutboundHeader);
		return page;
	}
	
	/**
	 * 查询子表数据
	 */
	@RequiresPermissions("otheroutbound:header:view")
	@RequestMapping(value = "linesListData")
	@ResponseBody
	public Page<OtherOutboundLines> subListData(OtherOutboundLines otherOutboundLines, HttpServletRequest request, HttpServletResponse response) {
		otherOutboundLines.setPage(new Page<>(request, response));
		Page<OtherOutboundLines> page = otherOutboundHeaderService.findSubPage(otherOutboundLines);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("otheroutbound:header:view")
	@RequestMapping(value = "form")
	public String form(OtherOutboundHeader otherOutboundHeader, Model model) {
		model.addAttribute("otherOutboundHeader", otherOutboundHeader);
		return "modules/otheroutbound/otherOutboundHeaderForm";
	}

	/**
	 * 保存数据
	 */
	@RequiresPermissions("otheroutbound:header:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated OtherOutboundHeader otherOutboundHeader) {
		otherOutboundHeaderService.save(otherOutboundHeader);
		return renderResult(Global.TRUE, text("保存其它出库单成功！"));
	}
	
	/**
	 * 删除数据
	 */
	@RequiresPermissions("otheroutbound:header:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(OtherOutboundHeader otherOutboundHeader) {
		otherOutboundHeaderService.delete(otherOutboundHeader);
		return renderResult(Global.TRUE, text("删除其它出库单成功！"));
	}
	
}